package com.ls.server.controller;

import com.ls.server.dto.ChatMessageDTO;
import com.ls.server.dto.ChatQueryDTO;
import com.ls.server.service.ChatMessageService;
import com.ls.server.vo.ChatMessageVO;
import com.ls.server.vo.PageResult;
import com.ls.server.vo.Result;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 聊天消息控制器
 */
@RestController
@RequestMapping("/chat/message")
public class ChatMessageController {

    private final ChatMessageService chatMessageService;

    public ChatMessageController(ChatMessageService chatMessageService) {
        this.chatMessageService = chatMessageService;
    }

    /**
     * 发送消息
     * @param dto 消息信息
     * @return 消息ID
     */
    @PostMapping("/send")
    public Result<Long> sendMessage(@RequestBody ChatMessageDTO dto) {
        return Result.success(chatMessageService.sendMessage(dto));
    }

    /**
     * 获取会话的所有消息
     * @param sessionId 会话ID
     * @return 消息列表
     */
    @GetMapping("/list/{sessionId}")
    public Result<List<ChatMessageVO>> listBySessionId(@PathVariable String sessionId) {
        return Result.success(chatMessageService.listSessionMessages(sessionId));
    }

    /**
     * 分页查询聊天消息
     * @param queryDTO 查询条件
     * @return 分页结果
     */
    @PostMapping("/page")
    public Result<PageResult<ChatMessageVO>> page(@RequestBody ChatQueryDTO queryDTO) {
        return Result.success(chatMessageService.page(queryDTO));
    }

    /**
     * 获取AI回复
     * @param sessionId 会话ID
     * @param prompt 用户输入
     * @param modelId 模型ID
     * @return AI回复内容
     */
    @GetMapping("/ai-response")
    public Result<String> getAiResponse(
            @RequestParam String sessionId,
            @RequestParam String prompt,
            @RequestParam Long modelId) {
        return Result.success(chatMessageService.getAiResponse(sessionId, prompt, modelId));
    }
} 